<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>航空主单对账</title>
        <% include("/common/common_css_js.html"){} %>
    </head>
    <body>
        <div style="padding-bottom: 5px;">
            <div id="queryForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">
                <span>主单号：</span><input id="keyMasterBillCode" name="keyMasterBillCode" emptyText="请输入主单号"  class="mini-textbox" selectOnFocus="true" required="false" requiredErrorText="主单号不能为空" />
                <span class="separator"></span>
                <span>配货方式:</span><input id="keyloadWayId" name="keyloadWayId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                                         required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择配货方式" />
                <span class="separator"></span>
                <span>承运方式:</span><input id="keyTransportWayId" name="keyTransportWayId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                                         required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择承运方式"/>

                <span class="separator"></span>
                <span>开单日期：</span>
                <input id="keyOpenMasterBillStartDate" name="keyOpenBillStartDate"  class="mini-datepicker"   format="yyyy-MM-dd"/>--<input id="keyOpenMasterBillEndDate" name="keyOpenBillEndDate" class="mini-datepicker"  format="yyyy-MM-dd"/>
                <span class="separator"></span>
                <span>目的市:</span>
                <input id="keyDestCityId" name="keyDestCityId" class="mini-treeselect"
                       virtualScroll="true"    multiSelect="false" valueField="id" textField="name" parentField="pid" allowInput="true" valueFromSelect="true"
                       style="width: 220px;" expandOnLoad="2" requiredErrorText="没有选择目的市" nullItemText="请选择..." />

                <div style="margin-top: 5px"></div>
                <span>始发机场:</span>
                <div id="keyAirportId" name="keyAirportId" class="mini-combobox" style="width:150px;"  popupWidth="1000" textField="name" valueField="id"
                     requiredErrorText="始发机场不能为空"
                     allowInput="true"
                     emptyText="始发机场名称">
                    <div property="columns">
                        <div header="ID" field="id" width="30"></div>
                        <div header="机场名称" field="name"></div>
                        <div header="简称" field="shortName"></div>
                    </div>
                </div>
                <span class="separator"></span>
                <span>外发单位:</span>
                <div id="keyOutUnitId" name="keyOutUnitId"
                     class="mini-combobox"
                     style="width:250px;"
                     popupWidth="600" textField="name" valueField="id"
                     allowInput="true" requiredErrorText="外发单位不能为空"
                     emptyText="外发单位名称">
                    <div property="columns">
                        <div header="ID" field="id" width="30"></div>
                        <div header="单位名称" field="name"></div>
                        <div header="联系人" field="contact"></div>
                        <div header="电话" field="phone"></div>
                        <div header="地址" field="address"></div>
                    </div>
                </div>
                <span class="separator"></span>
                <span>地面运费结费状态:</span>
                <input id="keyGroundAmountStatusId" name="keyGroundAmountStatusId" class="mini-combobox" style="width:120px;" textField="name" valueField="id" emptyText="请选择..."
                       required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择地面运费结费状态"/>
                <span class="separator"></span>
                <span>航空运费结费状态:</span>
                <input id="keyTransportCostStatusId" name="keyTransportCostStatusId" class="mini-combobox" style="width:120px;" textField="name" valueField="id" emptyText="请选择..."
                       required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择航空运费结费状态"/>

                <span class="separator"></span>
                <span>主单对账状态:</span>
                <input id="keyAccountCheckStatusId" name="keyAccountCheckStatusId" class="mini-combobox" style="width:120px;" textField="name" valueField="id" emptyText="请选择..."
                       required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择主单对账状态"/>

                <div style="margin-top: 5px"></div>
                <span>航空运费对账状态:</span>
                <input id="keyTransportCostAccountCheckStatusId" name="keyTransportCostAccountCheckStatusId" class="mini-combobox" style="width:120px;" textField="name" valueField="id" emptyText="请选择..."
                       required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择航空运费对账状态"/>

                <span>地面运费对账状态:</span>
                <input id="keyGroundAmountAccountCheckStatusId" name="keyGroundAmountAccountCheckStatusId" class="mini-combobox" style="width:120px;" textField="name" valueField="id" emptyText="请选择..."
                       required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择地面运费对账状态"/>


                <span>燃油附加费对账状态:</span>
                <input id="keyAirlinesAddCostAccountCheckStatusId" name="keyAirlinesAddCostAccountCheckStatusId" class="mini-combobox" style="width:120px;" textField="name" valueField="id" emptyText="请选择..."
                       required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择燃油附加费对账状态"/>

                <span>其他费用对账状态:</span>
                <input id="keyOtherChargesAccountCheckStatusId" name="keyOtherChargesAccountCheckStatusId" class="mini-combobox" style="width:120px;" textField="name" valueField="id" emptyText="请选择..."
                       required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择其他费用对账状态"/>

                <div style="margin-top: 5px"></div>
                <% if(so.hasPermission("airMasterBillReconciliation:query")){%>
                    <a class="mini-button" iconCls="icon-search" onclick="searchBill()">查询</a>
                <% } %>

                <% if(so.hasPermission("airMasterBillReconciliation:queryCndClear")){%>
                    <a class="mini-button" iconCls="icon-new" onclick="clearSearch()">清空查询条件</a>
                <% } %>

                <% if(so.hasPermission("airMasterBillReconciliation:confirm")){%>
                    <span class="separator"></span>
                    <a class="mini-button" iconCls="icon-lock" onclick="accountStatusChange(432)">主单确认对账</a>
                <% } %>

                <% if(so.hasPermission("airMasterBillReconciliation:cancel")){%>
                    <a class="mini-button" iconCls="icon-unlock" onclick="accountStatusChange(431)">主单取消对账</a>
                <% } %>

                <% if(so.hasPermission("airMasterBillReconciliation:download")){%>
                    <span class="separator"></span>
                    <#download_grid id="downloadGrid" theGridId="datagrid1" theFileName="航空主单对账表"/>
                <% } %>

                <div style="margin-top: 5px"></div>
                <% if(so.hasPermission("airMasterBillReconciliation:confirmTransportCost")){%>
                <a class="mini-button" iconCls="icon-lock" onclick="changeAccountCheckStatusByAccountType(432,0)">航空运费确认对账</a>
                <a class="mini-button" iconCls="icon-lock" onclick="showAccountPanel(0)">航空运费导入确认对账</a>
                <a class="mini-button" iconCls="icon-unlock" onclick="changeAccountCheckStatusByAccountType(431,0)">航空运费对账取消</a>
                <% } %>

                <% if(so.hasPermission("airMasterBillReconciliation:confirmGroundAmount")){%>
                <span class="separator"></span>
                <a class="mini-button" iconCls="icon-lock" onclick="changeAccountCheckStatusByAccountType(432,1)">地面操作费确认对账</a>
                <a class="mini-button" iconCls="icon-lock" onclick="showAccountPanel(1)">地面操作费导入确认对账</a>
                <a class="mini-button" iconCls="icon-unlock" onclick="changeAccountCheckStatusByAccountType(431,1)">地面操作费取消对账</a>
                <% } %>

                <div style="margin-top: 5px"></div>
                <% if(so.hasPermission("airMasterBillReconciliation:confirmAirlinesAddCost")){%>
                <a class="mini-button" iconCls="icon-lock" onclick="changeAccountCheckStatusByAccountType(432,2)">航空附加费确认对账</a>
                <a class="mini-button" iconCls="icon-lock" onclick="showAccountPanel(2)">航空附加费导入确认对账</a>
                <a class="mini-button" iconCls="icon-unlock" onclick="changeAccountCheckStatusByAccountType(431,2)">航空附加费取消对账</a>
                <% } %>

                <% if(so.hasPermission("airMasterBillReconciliation:confirmOtherCharges")){%>
                <span class="separator"></span>
                <a class="mini-button" iconCls="icon-lock" onclick="changeAccountCheckStatusByAccountType(432,3)">其他费用确认对账</a>
                <a class="mini-button" iconCls="icon-lock" onclick="showAccountPanel(3)">其他费用导入确认对账</a>
                <a class="mini-button" iconCls="icon-unlock" onclick="changeAccountCheckStatusByAccountType(431,3)">其他费用取消对账</a>
                <% } %>

                <a href="${base!}/hymj/files/航空主单对账模板.rar" target="_blank">点击下载《航空主单导入确认对账》模板</a>

                <div style="margin-top: 5px"></div>
                <span style="color: red;">如果主单结算状态是已结算，则不能取消对账</span>
            </div>
        </div>

        <div class = "mini-fit">
            <div id="datagrid1" class="mini-datagrid"
                 style="width: 100%; height: 100%;"
                 url="${base}/pages/finance_manage/reconciliation/queryFlightMasterBillReconciliationList" idField="id"
                 showPager="true" pageSize="20" sizeList="[10,20,30,50,100]"
                 multiSelect = "true" allowResize="true"
                 showGroupsSummary="true" showSummaryRow="true" summaryPosition="bottom"
                 allowSortColumn = "true"
                 sortField="createTime"
                 sortOrder="desc"
                 onshowrowdetail="onShowRowDetail"
                 ondrawsummarycell="summaryRight"
            >
                <div property="columns">
                    <div type="checkcolumn" ></div>
                    <div type="expandcolumn" ></div>
                    <div field="accountCheckStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">主单对账状态</div>

                    <div field="transportCostAccountCheckStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">航空运费对账状态</div>
                    <div field="groundAmountAccountCheckStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">地面运费对账状态</div>
                    <div field="airlinesAddCostAccountCheckStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">燃油附加费对账状态</div>
                    <div field="otherChargesAccountCheckStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">其他费用对账状态</div>

                    <div field="id" width="140" headerAlign="center" align="center" allowSort="true" renderer="showMasterBillRender">航空主单号</div>
                    <div field="airportId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"airport"}' renderer="commonRender">始发机场</div>
                    <div field="destCityId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"city"}' renderer="commonRender">目的市</div>
                    <div field="flightDate" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd" renderer="ondayRenderer">航班日期</div>
                    <div field="flightName" width="140" headerAlign="center" align="center" allowSort="true">航班名</div>

                    <div field="totalNumber" width="140" headerAlign="center" align="right" allowSort="false" summaryType="sum">总件数</div>
                    <div field="actualWeight" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">实重</div>
                    <div field="chargeableWeight" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">计重</div>
                    <div field="weightRate" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" >费率</div>
                    <div field="transportCost" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">航空运费</div>
                    <div field="groundAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">地面运费</div>
                    <div field="airlinesAddCost" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">航空附加费</div>
                    <div field="declaredValue" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">声明价值</div>
                    <div field="stampDuty" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">印花税</div>
                    <div field="insuranceFee" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">保险费</div>
                    <div field="otherCharges" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">其他费用</div>
                    <div field="otherChargesComment" width="140" headerAlign="center" align="center" allowSort="true">其他费用说明</div>
                    <div field="totalAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">总金额</div>
                    <div field="dropAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">拉货调整金额</div>
                    <div field="settlementAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">结算金额</div>
                    <div field="openMasterBillDate" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">开单日期</div>
                    <div field="airlinesId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"airlines"}' renderer="commonRender">航空公司</div>
                    <div field="loadWayId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">配货方式</div>
                    <div field="transportWayId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">承运方式</div>
                    <div field="outUnitId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"outUnit"}' renderer="commonRender">外发单位</div>

                    <div field="agentCompanyName" width="140" headerAlign="center" align="center" allowSort="true">代理公司名</div>
                    <div field="agentCompanyPhone" width="140" headerAlign="center" align="center" allowSort="true">代理公司电话</div>
                    <div field="agentCompanyAddress" width="140" headerAlign="center" align="center" allowSort="true">代理公司地址</div>
                    <div field="goodsTypeId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">货物类型</div>

                    <div field="groundAmountStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">地面运费状态</div>
                    <div field="transportCostStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">航空运费状态</div>

                    <div field="freightSpeciesId" width="140" headerAlign="center" align="center" allowSort="true">运价种类</div>
                    <div field="goodsCodeId" width="140" headerAlign="center" align="center" allowSort="true">商品代号</div>
                    <div field="goodsName" width="140" headerAlign="center" align="center" allowSort="true" >货物名称</div>
                    <div field="packingWayId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">包装方式</div>
                    <div field="airportGoodsSiteId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"airportGoodsSite"}' renderer="commonRender">航空货站</div>

                    <div field="masterBillPaymentMethodId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">付款方式</div>

                    <div field="dropStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">拉货状态</div>

                    <div field="settlementStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">结算状态</div>

                    <div field="openMasterBillDepartmentId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"department"}' renderer="commonRender">开单部门</div>
                    <div field="openMasterBillUserId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysUser"}' renderer="commonRender">开单人</div>
                    <div field="comment" width="140" headerAlign="center" align="center" allowSort="false">备注</div>

                </div>
            </div>
        </div>

        <!-- 子表 -->
        <div id="detailDiv" style="display:none; margin-left: 50px">
            <div id="detailGrid" class="mini-datagrid" style="width:850px;height:350px;"
                 url="${base}/pages/master_bill_manage/flight/queryNativeBillList">
                <div property="columns">
                    <div field="nativeBillId" width="50" headerAlign="center" align="center" renderer="showNativeBillRender">分单号</div>
                    <div field="loadNumber" width="70" headerAlign="center" align="right" >配载总件数</div>
                    <div field="loadActualWeight" width="70" headerAlign="center" align="right" >配载实际重量</div>
                    <div field="loadChargeableWeight" width="70" headerAlign="center" align="right" >配载计费重量</div>
                    <div field="loadVolume" width="70" headerAlign="center" align="right" >配载体积</div>
                    <div field="airlinesId" width="140" headerAlign="center" align="left" data-options='{cacheName:"airlines"}' renderer="commonRender">配载航空公司</div>
                    <div field="flightName" width="70" headerAlign="center" align="center" >配载航班</div>
                    <div field="flightDate" width="70" headerAlign="center" align="center" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">航班日期</div>
                </div>
            </div>
        </div>



        <!-- 对账数据上传 -->
        <div id="accountPanel" class="mini-window" title="对账数据上传" style="width:800px;height:600px;"
             showMaxButton="true" showCollapseButton="false" showMinButton="true" showShadow="true"
             showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true" >
            <div property="footer" style="padding:10px;text-align: right">
                <a  id="uploadBtn" name="uploadBtn" class="mini-button" iconCls="icon-upload" onclick="uploadAccount()">上传并对账</a>
                <a  class="mini-button" iconCls="icon-close" onclick="public_onCancel('accountPanel')">关闭</a>
            </div>


            <span id="fileTitle">文件:</span>
            <form id="upload-form-add" style="display: inline">
                <input type="file" id="upLoadAccountFileData" name="upLoadFileData"  accept=".xls,.xlsx" />
            </form>


            <div style="height: 5px"></div>
            <span>对账结果:</span>
            <div style="height: 5px"></div>
            <div id="accountResult" style="color: red">

            </div>

        </div>




        <script type="text/javascript">
            mini.parse();

            let keyMasterBillCode = mini.get("keyMasterBillCode");
            let keyloadWayId = mini.get("keyloadWayId");
            let keyTransportWayId = mini.get("keyTransportWayId");
            let keyOpenMasterBillStartDate = mini.get("keyOpenMasterBillStartDate");
            let keyOpenMasterBillEndDate = mini.get("keyOpenMasterBillEndDate");
            let keyGroundAmountStatusId = mini.get("keyGroundAmountStatusId");
            let keyTransportCostStatusId = mini.get("keyTransportCostStatusId");
            let keyAccountCheckStatusId = mini.get("keyAccountCheckStatusId");

            let keyDestCityId = mini.get("keyDestCityId");
            let keyAirportId = mini.get("keyAirportId");
            let keyOutUnitId = mini.get("keyOutUnitId");


            let keyTransportCostAccountCheckStatusId = mini.get("keyTransportCostAccountCheckStatusId");
            let keyGroundAmountAccountCheckStatusId = mini.get("keyGroundAmountAccountCheckStatusId");
            let keyAirlinesAddCostAccountCheckStatusId = mini.get("keyAirlinesAddCostAccountCheckStatusId");
            let keyOtherChargesAccountCheckStatusId = mini.get("keyOtherChargesAccountCheckStatusId");

            // 主 grid
            let grid = mini.get("datagrid1");

            // 明细 grid块
            let detailDiv = document.getElementById("detailDiv");

            let detailGrid = mini.get("detailGrid");

            let fileTitle = document.getElementById("fileTitle");

            let accountResult = document.getElementById("accountResult");

            $(function () {

                // 配货方式
                let keyloadWayIdJsonData=commonRenderSysDicDropListByKey("sysDic","XT_DIC_LOAD_WAY");
                keyloadWayId.load(keyloadWayIdJsonData);

                // 承运方式下拉列表
                let keyTransportWayIdJsonData=commonRenderSysDicDropListByKey("sysDic","XT_DIC_TRANSPORT_WAY");
                keyTransportWayId.load(keyTransportWayIdJsonData);

                // 地面运费结费状态
                let keyGroundAmountStatusIdJsonData=commonRenderSysDicDropListByKey("sysDic","XT_DIC_SETTLEMENT_STATUS");
                keyGroundAmountStatusId.load(keyGroundAmountStatusIdJsonData);

                // 航空运费结费状态
                let keyTransportCostStatusIdJsonData=public_deepClone(keyGroundAmountStatusIdJsonData);
                keyTransportCostStatusId.load(keyTransportCostStatusIdJsonData);

                // 对账状态
                let keyAccountCheckStatusIdJsonDate  = commonRenderSysDicDropListByKey("sysDic","XT_DIC_ACCOUNT_CHECK_STATUS");
                keyAccountCheckStatusId.load(keyAccountCheckStatusIdJsonDate);
                keyTransportCostAccountCheckStatusId.load(public_deepClone(keyAccountCheckStatusIdJsonDate));
                keyGroundAmountAccountCheckStatusId.load(public_deepClone(keyAccountCheckStatusIdJsonDate));
                keyAirlinesAddCostAccountCheckStatusId.load(public_deepClone(keyAccountCheckStatusIdJsonDate));
                keyOtherChargesAccountCheckStatusId.load(public_deepClone(keyAccountCheckStatusIdJsonDate));

                // 加载目的城市下拉列表
                let keyDestCityIdJsonData=commonRenderDropList("city");
                keyDestCityId.loadList(keyDestCityIdJsonData,"id","pid");

                // 加载外发单位下拉列表
                let outUnitIdJsonData = commonRenderDropList("outUnit");
                keyOutUnitId.load(outUnitIdJsonData);

                // 始发机场下拉列表
                let pullAirportIdJsonData = commonRenderDropList("airport");
                keyAirportId.load(pullAirportIdJsonData);

                // 加载列表数据
                grid.load();
            });

            /**
             * 清空查询条件
             */
            function clearSearch(){
                let form = new mini.Form("#queryForm");
                form.clear();
            }

            /**
             * 根据查询条件查询分单
             */
            function searchBill(){
                let form = new mini.Form("#queryForm");
                let data = form.getData(true);
                grid.load(data);
            }

            /**
             * 加载明细
             */
            function onShowRowDetail(e){
                let grid = e.sender;
                let row = e.record;

                let td = grid.getRowDetailCellEl(row);
                td.appendChild(detailDiv);

                detailDiv.style.display = "block";

                detailGrid.load({masterBillId: row.id});

            }


            // 展示主单号时显示其超链接
            function showMasterBillRender(e){
                // renderer="showMasterBillRender"

                let masterBillId = e.value;
                let billType = e.record.masterBillTypeId;
                let htmlStr = "<a href='javascript:void(0);' onclick='showViewMasterBill(\""+ masterBillId +"\")'>" + masterBillId + "</a>";

                return htmlStr;
            }

            function showViewMasterBill(masterBillId){
                let tabUrl= "${base}/pages/master_bill_manage/flight/showUpdateMasterBill?opType=view&id=" + masterBillId;
                let tabTitle = "航空主单查看";
                parent.window.addTabToMainPage(tabTitle,tabTitle,tabUrl);
            }


            function showNativeBillRender(e){
                //  renderer="showNativeBillRender"
                let nativeBillId = e.value;
                let htmlStr = "<a href='javascript:void(0);' onclick='showViewNativeBill(\""+ nativeBillId +"\")'>" + nativeBillId + "</a>";
                return htmlStr;
            }

            function showViewNativeBill(nativeBillId){
                let tabUrl="${base}/pages/native_bill_manage/showUpdateBill?opType=view&id=" + nativeBillId;
                parent.window.addTabToMainPage("分单查看","分单查看",tabUrl);
            }



            /**
             * 320,0,结算状态,结算状态,XT_DIC_SETTLEMENT_STATUS
             * 321,320,未结算,未结算,""
             * 322,320,已结算,已结算,""
             *
             *
             * 430,0,分单主单对账状态,分单主单对账状态,XT_DIC_ACCOUNT_CHECK_STATUS
             * 431,430,未对账,未对账,
             * 432,430,已对账,已对账,

             */
            let settlementStatus = {uncleared:321, cleared:322};

            let accountCheckStatus = {noCheck:431, checked:432};

            /**
             * 主单对账
             */
            function accountStatusChange(accountStatus){
                let selectItems = grid.getSelecteds();
                if(selectItems.length==0){
                    showAlert("请选择需要改变对账状态的主单!");
                    return;
                }

                let canAccountCheckIds = "";
                let canNotAccountCheckIds = "";

                if(accountStatus == accountCheckStatus.noCheck){
                    for(let obj of selectItems){
                        if(obj.settlementStatusId == settlementStatus.cleared){
                            canNotAccountCheckIds += obj.id + " ";
                        }
                        else{
                            canAccountCheckIds += "'" + obj.id + "',"
                        }
                    }
                }
                else{
                    for(let obj of selectItems){
                        canAccountCheckIds += "'" + obj.id + "',"
                    }
                }

                if(canNotAccountCheckIds.length>0){
                    canNotAccountCheckIds = canNotAccountCheckIds.substring(0,canNotAccountCheckIds.length-1);
                    showAlert("取消对账状态的主单号【" + canNotAccountCheckIds +  "】中包含已经结算的主单，不能修改其对账状态为未对账!");
                    return;
                }

                let title = accountStatus == accountCheckStatus.checked?"确认对账?":"取消对账?";
                canAccountCheckIds = canAccountCheckIds.substring(0,canAccountCheckIds.length-1);
                // 给出确认提示框
                mini.confirm("确定为主单【" + canAccountCheckIds + "】"+ title, "对账提示",
                    function (action) {
                        if (action == "ok") {
                            let ret = public_getServerData("${base}/pages/master_bill_manage/flight/changeAccountCheckStatus",{billIds:canAccountCheckIds,accountCheckStatusId:accountStatus});
                            showAlert(ret.message,function (){
                                if(ret.ok){
                                    grid.reload();
                                }
                            });
                        }
                    }
                );


            }

            /**
             * 设置底部统计样式
             * @param e
             */
            function summaryRight(e){
                e.cellStyle="text-align:right;color:red;font-size:18px;font-weight:bold";
            }

            /**
             * 主单运费、地面操作费、航空附加费、其他费用对账
             * accountType:
             * 0:航空运费
             * 1:地面操作费
             * 2:航空附加费
             * 3:其他费用
             */
            function changeAccountCheckStatusByAccountType(accountStatus,accountType){

                let selectItems = grid.getSelecteds();
                if(selectItems.length==0){
                    showAlert("请选择需要改变对账状态的主单!");
                    return;
                }

                let canAccountCheckIds = "";
                let canNotAccountCheckIds = "";

                if(accountStatus == accountCheckStatus.noCheck){
                    for(let obj of selectItems){
                        if(obj.settlementStatusId == settlementStatus.cleared){
                            canNotAccountCheckIds += obj.id + " ";
                        }
                        else{
                            canAccountCheckIds += "'" + obj.id + "',"
                        }
                    }
                }
                else{
                    for(let obj of selectItems){
                        canAccountCheckIds += "'" + obj.id + "',"
                    }
                }

                if(canNotAccountCheckIds.length>0){
                    canNotAccountCheckIds = canNotAccountCheckIds.substring(0,canNotAccountCheckIds.length-1);
                    if(accountType == 0){
                        showAlert("取消航空运费对账状态的主单号【" + canNotAccountCheckIds +  "】中包含已经结算的主单，不能修改主单航空运费对账状态为未对账!");
                    }
                    else if(accountType == 1){
                        showAlert("取消地面操作费对账状态的主单号【" + canNotAccountCheckIds +  "】中包含已经结算的主单，不能修改主单地面操作费对账状态为未对账!");
                    }
                    else if(accountType == 2){
                        showAlert("取消航空附加费对账状态的主单号【" + canNotAccountCheckIds +  "】中包含已经结算的主单，不能修改主单航空附加费对账状态为未对账!");
                    }
                    else{
                        showAlert("取消其他费用对账状态的主单号【" + canNotAccountCheckIds +  "】中包含已经结算的主单，不能修改主单其他费用对账状态为未对账!");
                    }
                    return;
                }

                let title = accountStatus == accountCheckStatus.checked?"确认对账?":"取消对账?";
                canAccountCheckIds = canAccountCheckIds.substring(0,canAccountCheckIds.length-1);
                // 给出确认提示框
                mini.confirm("主单【" + canAccountCheckIds + "】"+ title, "对账提示",
                    function (action) {
                        if (action == "ok") {
                            let ret = public_getServerData("${base}/pages/master_bill_manage/flight/changeAccountCheckStatusByAccountType",{billIds:canAccountCheckIds,accountCheckStatusId:accountStatus,accountTypeId:accountType});
                            showAlert(ret.message,function (){
                                if(ret.ok){
                                    grid.reload();
                                }
                            });
                        }
                    }
                );

            }


            // 对账文件类型
            let accountFileType;
            let fileTitleValue;
            /**
             * 对账数据上传
             */
            function showAccountPanel(accountType){

                if(accountType == 0){
                    fileTitleValue = "航空运费对账文件";

                }
                else if(accountType == 1){
                    fileTitleValue = "地面操作费对账文件";
                }
                else if(accountType == 2){
                    fileTitleValue = "航空附加费对账文件";
                }
                else if(accountType == 3){
                    fileTitleValue = "其他费用对账文件";
                }

                fileTitle.innerText = fileTitleValue + ":";
                accountFileType = accountType;

                let form_add = new mini.Form("#upload-form-add");
                form_add.clear();

                accountResult.innerHTML = "";

                    // 弹出添加窗口
                public_showModelAtPos("accountPanel", "center", "middle");
            }


            function uploadAccount() {
                // 上传并对账
                let fileInput = $('#upLoadAccountFileData').get(0).files[0];
                if(fileInput){
                    mini.confirm("您确认上传" + fileTitleValue + "数据?", "提示", function(confirmAction){
                        if(confirmAction == "ok"){
                            let messageid = mini.loading("正在上传校验及上传处理中，请稍后...","对账文件Excel上传");
                            flightAjaxFileUpload(messageid);
                        }
                    });
                }else{
                    mini.alert("没有选择要上传的对账信息数据Excel文件!");
                }

            }

            // 调用异步上传
            function flightAjaxFileUpload(messageid) {
                let formData = new FormData($("#upload-form-add")[0]);
                $.ajax({
                    //接口地址
                    url: '${base}/pages/master_bill_manage/flight/accountFileUploadAndCheck?accountFileType='+ accountFileType ,
                    type: 'POST',
                    data: formData,
                    async: false,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (data) {

                        mini.hideMessageBox(messageid);

                        accountResult.innerHTML = data.message;

                        // 清空上传对象
                        clearUploadFile("upload-form-add");

                        // 重新刷新数据
                        grid.reload();

                    },
                    error: function (returndata) {
                        mini.alert("网络异常，请重试！");
                    }
                });
            }


        </script>

    </body>
</html>